package co.edu.unal.satacredito.administration.view.monitor;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.NoneScoped;
import javax.faces.context.FacesContext;

import co.edu.unal.satacredito.administration.view.general.AdministrationBean;
import co.edu.unal.satacredito.infrastructure.dto.EventDTO;
import co.edu.unal.satacredito.infrastructure.dto.MachineDTO;
import co.edu.unal.satacredito.mediation.InfraestructureEJBLocal;

@ManagedBean(name = "infraestructureBean")
@NoneScoped
public class InfraestructureBean extends AdministrationBean {


	private String name;
	private String ip;
	private String state;
	private List<MachineDTO> machines;
	private List<EventDTO> log;

	
	@EJB
	InfraestructureEJBLocal infraestructureEJB;

	@PostConstruct
	public void init() {
		this.machines = infraestructureEJB.getMachines();
	}

	public String doSeeLog() {
		Map<String, String> params = FacesContext.getCurrentInstance()
				.getExternalContext().getRequestParameterMap();
		
		name = params.get("name");
		
		this.log = infraestructureEJB.getLog(name);
		
		return SEE_EVENT_LOG;
	}
	
	public String Deactivate() {
		Map<String, String> params = FacesContext.getCurrentInstance()
				.getExternalContext().getRequestParameterMap();
		infraestructureEJB.deactivate(params.get("name"));
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("infraestructureBean");
		return REFRESH_INFRAESTRUCTURE;
	}

	public List<MachineDTO> getMachines() {
		return machines;
	}

	public List<EventDTO> getLog() {
		return log;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
	
	
}
